using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GameManager : MonoBehaviour
{
    [SerializeField] GameObject GameOver;
    [SerializeField] GameObject pauseScreen;
    [SerializeField] PlayerControl playerControl;
    [SerializeField] GameObject[] LivesContainer;
    [SerializeField] GameObject Player;
    public static bool isActivateGame = true;
    public static bool isPauseGame = false;
    public TextMeshProUGUI scoreText;
    public static int score = 0;

    private void Awake()
    {

        scoreText.text = "0";
    }

    private void Update()
    {
        scoreText.text = score.ToString();
        LivesShow(playerControl.liveNum);
        if (!isActivateGame)
        {
            GameOver.SetActive(true);
        }
    }

    void AddScore()
    {

    }

    public void RestartGame()
    {
        //GameOver.SetActive(false);
        isActivateGame = true;
        //GameObject newPlayer = Instantiate(Player);
        //newPlayer.GetComponent<PlayerControl>().LivesShow = LivesShow;
        SceneManager.LoadScene(1); 
    }

    public void PauseGame()
    {
        Time.timeScale = 0;
        isPauseGame = true;
        pauseScreen.SetActive(true);
    }

    public void PauseQuit()
    {
        Time.timeScale = 1;
        isPauseGame = false;
        pauseScreen.SetActive(false);
    }

    void LivesShow(int num)
    {

        for (int i = 0; i < LivesContainer.Length; i++)
        {
            LivesContainer[i].gameObject.SetActive(false);
        }
        for(int i = 0; i < num; i++)
        {
            LivesContainer[i].gameObject.SetActive(true);
        }
    }
}
